import viewer from './viewer';
import Entities from './entities';
import Draw from './draw';
import Layer from './layer';
import Measure from './measure';

function Viewer(containerId) {
    this.viewer = viewer.init(containerId);
    this.entities = new Entities(this.viewer); //实体方法二次封装
    this.draw = new Draw(this.viewer); //绘图方法二次封装
    this.layer = new Layer(this.viewer); //图层加载二次封装
    this.measure = new Measure(this.viewer); //测量二次封装
}

Viewer.prototype.destroy = function () {
    if (this.viewer) {
        // 清理实体、图层和数据源
        this.viewer.entities.removeAll();
        this.viewer.imageryLayers.removeAll();
        this.viewer.dataSources.removeAll();

        // 清理 WebGL 上下文
        let gl = this.viewer.scene.context._originalGLContext;
        gl.canvas.width = 1;
        gl.canvas.height = 1;
        gl.getExtension('WEBGL_lose_context').loseContext();
        gl = null;

        // 销毁 Viewer 实例
        this.viewer.destroy();
    }
};

export default Viewer;
